package ar.com.sne.model.composer.per;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.zkoss.zk.ui.Component;
import org.zkoss.zul.Window;

import foundation.common.util.BusinessException;
import foundation.common.util.CommonWebUtil;
import foundation.zk.crud.composer.AbstractCRUDEditComposer;
import ar.com.sne.model.bo.geo.GeoTelefono;
import ar.com.sne.model.bo.per.PerPersona;
import ar.com.sne.model.service.geo.GeoTelefonoService;

@Service
@Scope("prototype")
public class EdicionTelefonosComposer extends AbstractCRUDEditComposer {

	private final Log log = LogFactory.getLog(getClass());

	@Resource
	private GeoTelefonoService GeoTelefonoService;
	
	private Window wndEditTelefonosTelefonos;
	private PerPersona perPersona;
	
	@Override
	public void doAfterCompose(Component comp) throws Exception {
		super.doAfterCompose(comp);
		perPersona =(PerPersona)CommonWebUtil.getParameter(PerPersona.class.getSimpleName());
	}
	
	
	
	public GeoTelefono getEditedObject() {
		return (GeoTelefono) super.getEditedObject();
	}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * coop.foundation.zk.crud.composer.AbstractCRUDEditComposer#updateObject
	 * (java.lang.Object)
	 */
	
	@Override
	protected void updateObject(Object objectToUpdate) {
		GeoTelefono geoTelefono = (GeoTelefono)objectToUpdate;
		geoTelefono.setActivado("1");
		geoTelefono.setPerPersonas(perPersona);
		GeoTelefonoService.save(geoTelefono);
	}

	
	@Override
	protected void verify(BusinessException be) {
		
		if(this.getEditedObject().getNumero()==null){
			be.addExceptionKey("EdicionGeoTelefonosComposer.validate.numero.requerido");
		}	
		
	}
	
	@Override
	protected Object getNewObjectToAdd() {
		return new GeoTelefono();
	}

}